<?php
/**
 * Created by IntelliJ IDEA.
 * User: HXL
 * Date: 2018/5/9
 * Time: 12:26
 */
namespace app\order\model;

use think\Db;
/**
 * 基表型号
 * Class MeterTypes
 * @package app\order\model
 */
class MeterTypes extends BaseModel{
    protected $tableName = 'ari_meter_types';

    public function insertAll($data){
        $insertAll = Db::table($this->tableName)->insertAll($data);
        return $insertAll;
    }
    public function select($field = '*', $where=''){
        $result = Db::table($this->tableName)->field($field)->where($where)->order('meter_type desc')->select();
        return $result;
    }
    /**
     * 模糊查询
     * @return \think\paginator\Collection
     */
    public function searchLike($search){
        $count = Db::table($this->tableName)->where('meter_id', 'like', "%$search%")->whereOr('meter_type', 'like', "%$search%")->count();
        $meterTypes = Db::table($this->tableName)->where('meter_id', 'like', "%$search%")->whereOr('meter_type', 'like', "%$search%")
            ->whereOr('caliber', 'like', "%$search%")
            ->paginate(10, $count, ['query' => request()->param()]);
        return $meterTypes;
    }

    public function page($field, $where = '', $order = '')
    {
        $num = 10;
        $count = $this->count($where);
        $data = Db::table($this->tableName)->field($field)->where($where)
            ->order($order)->order('meter_type')
            ->paginate($num, $count, ['query' => request()->param()]);
        return $data;
//        return parent::page($field, $where, $order);
    }


}